<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: index.phtml 4185 2010-08-01 16:31:02Z huuphuoc $
 * @since		2.0.0
 */
?>
<?php
$this->headTitle($this->translator('dashboard_index_page_title'));

/**
 * Dashboard editor
 * @since 2.0.7
 */
$this->headLink()
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.core.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.resizable.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.dialog.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.tabs.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.theme.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.datepicker.css');

$this->headScript()
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.core.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.tabs.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.sortable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.draggable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.droppable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.resizable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.dialog.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.datepicker.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/tomato/core/colorconverter.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/tomato/core/layout.lang.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/tomato/core/layout.container.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/tomato/core/layout.widget.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/tomato/core/layout.defaultoutput.js');
?>

<style>
	.t_a_ui_breadcrumb_1{
		border-bottom: 1px solid #3D3D3D;
		font-size: 13px;
		font-weight: bold;
		height: 30px;
		line-height: 30px;
		width: 100%;
	}
	.t_a_ui_data_list_header
	{
		color: #CCCCCC;
	}
	a .t_a_ui_helper_line{
		text-decoration: none;
	}
	a:hover .t_a_ui_helper_line{
		text-decoration: underline;
	}
</style>

<div class="grid_12 t_a_top t_a_bottom">
	<div class="grid_9 alpha"><?php echo $this->translator('dashboard_index_guide'); ?></div>
	
	<div class="grid_3 omega">
		<div class="t_a_right">
			<a href="javascript: void(0);" class="t_a_ui_button_link" id="customizeButton"><span><?php echo $this->translator('dashboard_index_customize_button'); ?></span></a>
		</div>
	</div>
</div>

<!-- Loading -->
<div id="loading" class="grid_12 t_a_bottom" style="display: none">&nbsp;</div>

<!-- Editor -->
<div class="grid_12 t_a_bottom t_a_ui_tabs" id="editor" style="display: none"></div>

<!-- Buttons for previewing/saving Dashboard layout -->
<div class="grid_12 t_a_bottom" id="layoutButtons" style="display: none">
	<h3><?php echo $this->translator('dashboard_index_layout'); ?></h3>
	<hr />
	
	<div class="t_a_textright">
		<button id="switchButton"><span><?php echo $this->translator('dashboard_index_preview_button'); ?></span></button>
		<button id="saveButton"><span><?php echo $this->translator('dashboard_index_save_button'); ?></span></button>
	</div>
</div>

<!-- Start: Thong tin DN - SP moi nhat - Danh sach don dat hang - Assignment -->
<?php if($this->enterprise_user_accounts == 1):?>
<div class="grid_12 t_a_top t_a_bottom">
	<div class="grid_9 alpha" style="width: 600px;">
	<?php foreach ($this->enterprise as $row) : ?>
		<?php
            /**
            * Check expiry date
            */
            $valid_date = '&nbsp';
            $class = null;
            if(isset($this->arValidDate[$row->id])){
                $valid_date = $this->arValidDate[$row->id]->account_valid_until_date;
                $current_date = strtotime(date('Y-m-d'));
                if(strtotime($valid_date) < $current_date){
                    $class = "css_expired";
                }
            }else{
                $class = "css_expired";
            }
        ?>
        
        <!-- 
        --	Thong tin Doanh nghiep
        -->
        <?php if($this->allow('list', 'enterprise', 'enterprise')):?>
        <div class="grid_4 alpha"  style="width: 600px">
        	<div class="t_a_ui_helper_line">
		        <a href="<?php echo $this->url(array(), 'enterprise_enterprise_list'); ?>"><h3><?php echo $this->translator('dashboard_index_enterprise_info');?></h3></a>
		    </div>
		    <div class="t_a_top t_a_ui_helper_action" style="margin-top: 0;">
		    	<div style="width: 90%; float: left; color: #ccc; font-size: 12px;">
		    		<?php echo $row->company_name_vn;?>
		    	</div>
		       	<div style="width: 90%; float: left;">
			    	<?php if ($this->allow('edit', 'enterprise', 'enterprise')) : ?>
	                <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_edit'); ?>"><?php echo $this->translator('enterprise_list_action_edit', 'enterprise'); ?></a>
	                <?php endif; ?>
	
	                <?php if ($this->allow('payment-info', 'enterprise', 'enterprise')) : ?>
	                 | <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_payment_info'); ?>"><?php echo $this->translator('enterprise_list_action_edit_payment_info', 'enterprise'); ?></a>
	                <?php endif; ?>
	
	                <?php if ($this->allow('enterprise-info', 'enterprise', 'enterprise')) : ?>
	                 | <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_info'); ?>/vi_VN"><?php echo $this->translator('enterprise_list_action_edit_enterprise_info_vn', 'enterprise'); ?></a>
	                 | <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_info'); ?>/en_US"><?php echo $this->translator('enterprise_list_action_edit_enterprise_info_en', 'enterprise'); ?></a>
	                <?php endif; ?>
	
	                <?php if ($this->allow('user-account', 'enterprise', 'enterprise')) : ?>
	                 | <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_user_account'); ?>"><?php echo $this->translator('enterprise_list_action_edit_user_account', 'enterprise'); ?></a>
	                <?php endif; ?>
				</div>	                
		    </div>
       	</div> 
       	<?php endif;?>
       	
       	<!-- 
        -- San pham moi nhat
        -->
       	<?php if($this->allow('list', 'product', 'shop')):?>
        <div class="grid_4 alpha"  style="width: 600px; margin-top: 10px;">
        	<!--div class="t_a_ui_data_list_header" style="padding-left: 5px;">
				<?php echo $this->translator('dashboard_list_product', 'shop');?>
			</div-->
        	<div class="t_a_ui_helper_line">
		        <a href="<?php echo $this->url(array(), 'shop_product_list'); ?>"><h3><?php echo $this->translator('dashboard_index_product_list');?></h3></a>
		    </div>
			<?php if ($this->numProduct == 0) : ?>
			<div class="t_a_bottom"><?php echo $this->translator('product_list_not_found', 'shop'); ?></div>
			<?php else:?>
			<div class="t_a_ui_data_list_header" style="background-color: none;">
				<div class="grid_4 alpha" style="width: 200px;">
			        <div><?php echo $this->translator('product_main_title', 'shop'); ?></div>
			    </div>
				<div class="grid_5" style="width: 200px;"><?php echo $this->translator('product_content_name', 'shop'); ?></div>
		        <div class="grid_2" style="width: 80px;"><?php echo $this->translator('product_status', 'shop'); ?></div>
		        <div class="grid_1 omega" style="width: 50px;"><?php echo $this->translator('product_id', 'shop'); ?></div>
			</div>
			<div>
				<?php $i=0;?>
				<?php foreach ($this->product as $row) : ?>
				<?php if($i<10):?>
				<div id="tArticleRow_<?php echo $row->product_id; ?>" class="clearfix t_a_ui_data_list_content">
					<div class="grid_4 alpha" style="width: 200px;">
		                <div>
		                    <a href="<?php echo $this->url(array('product_id' => $row->product_id), 'shop_product_edit'); ?>"><?php echo $row->product_admin_name?></a>
		                </div>
		
		                <div class="t_a_top t_a_ui_helper_action">
		                    <?php if ($this->allow('edit', 'product', 'shop')) : ?>
		                    <a href="<?php echo $this->url(array('product_id' => $row->product_id), 'shop_product_edit'); ?>"><?php echo $this->translator('product_list_action_edit', 'shop'); ?></a>
		                    <?php endif; ?>
		
		                    <?php if ($this->allow('delete', 'product', 'shop')) : ?>
		                     | <a class="deleteAction" rel="<?php echo $row->product_id; ?>" href="javascript: void(0);"><?php echo $this->translator('product_list_action_delete', 'shop'); ?></a>
		                    <?php endif; ?>
		
		                    <?php if ($this->allow('duplicate', 'product', 'shop')) : ?>
		                     | <a class="duplicateAction" rel="<?php echo $row->product_id; ?>" href="javascript: void(0);"><?php echo $this->translator('product_list_action_duplicate', 'shop'); ?></a>
		                    <?php endif; ?>
		                </div>
		            </div>
		            <div class="grid_5" style="width: 200px;">
		                <?php echo ($this->arrPoductContentName[$row->product_id])?$this->arrPoductContentName[$row->product_id]:'-'; ?>
		            </div>
		            <div class="grid_2" style="width: 80px;" id="tAricleStatus_<?php echo $row->product_id; ?>">
		                <?php if($row->product_status == 1):?>
		                <?php echo $this->translator('product_status_active', 'shop'); ?>
		                <?php else:?>
		                <font color="Red"><?php echo $this->translator('product_status_inactive', 'shop'); ?></font>
		                <?php endif;?>
		            </div>
		            <div class="grid_1 omega" style="width: 50px;"><?php echo $row->product_id;?></div>
				</div>
				<?php $i++;?>
				<?php endif;?>
				<?php endforeach;?>
			</div>
			<?php endif;?>
        </div>
        <?php endif;?>
	<?php endforeach;?>
	</div>
	
	<div class="grid_3 omega" style="width: 320px;">
		<!-- 
		--	Danh sach don dat hang 
		-->
		<?php if($this->allow('list', 'order', 'shop')):?>
		<div class="t_a_ui_helper_line">
	        <a href="<?php echo $this->url(array(), 'order_order_list'); ?>"><h3><?php echo $this->translator('dashboard_index_order_list');?></h3></a>
	    </div>
	    <?php if ($this->numOrder == 0) : ?>
		<div class="t_a_bottom" style="width: 320px; float: left;">
		    <?php echo $this->translator('order_list_not_found', 'shop'); ?>
		</div>
		<?php else : ?>
		<div class="t_a_ui_data_list_header">
        	<div style="padding-left: 5px; float: left; width: 105px;"><?php echo $this->translator('assignment_order_id', 'assignment'); ?></div>
        	<div style="float: left;"><?php echo $this->translator('order_customer', 'shop'); ?></div>
        </div>
        <div class="t_a_bottom" id="orders">
        <?php $i = 0;?>
        <?php foreach ($this->order as $row) : ?>
        <?php if($i<5):?>
        	<?php
	            /**
	            * To view
	            **/
	            $t_amount = $row->order_total_amount.$row->order_total_amount_currency;
	            $amount = $t_amount;
	
	            /**
	            * Customer info
	            **/
	            $customer = isset($this->arrCustomer[$row->order_id])?$this->arrCustomer[$row->order_id]:null;
	            $c_name = '-';
	            if($customer){
	                $c_name = $customer->full_name?$customer->full_name:$customer->user_name;
	
	                /**
	                * Enterprise name
	                **/
	                $enterprise = isset($this->arrEName[$row->order_id.'_'.$customer->user_id])?$this->arrEName[$row->order_id.'_'.$customer->user_id]:null;
	                $e_name = null;
	                if($enterprise){
	                    $e_name = $enterprise;
	                }
	            }
	
	            /**
	             * Tracking status
	            **/
	            $t_status = isset($this->arrStatus[$row->order_id])?$this->arrStatus[$row->order_id]:null;
	
	            /**
	             * Evaluation
	            **/
	            $evaluation = $this->arrEvalOrders[$row->order_id];
	        ?>
	        <div id="tOrderRow_<?php echo $row->order_id; ?>" class="clearfix t_a_ui_data_list_content">
	        	<div class="grid_2 alpha" style="width: 90px;">
	                <?php echo $row->order_invoice; ?>
	                <div class="t_a_top t_a_ui_helper_action">
	                    <?php if ($this->allow('view', 'order', 'shop')) : ?>
	                    <a href="<?php echo $this->url(array('order_id' => $row->order_id), 'order_order_view'); ?>"><?php echo $this->translator('order_list_action_view', 'shop'); ?></a>
	                    <?php endif; ?>
	                    <?php if ($this->allow('delete', 'order', 'shop')) : ?>
	                    | <a class="tDeleteAction" rel="<?php echo $row->order_id; ?>" href="javascript: void(0)"><?php echo $this->translator('order_list_action_delete', 'shop'); ?></a>
	                    <?php endif; ?>
	                </div>
	            </div>
	            <div class="grid_2" style="width: 200px;">
	                <b><?php echo $this->translator('order_customer_id', 'shop');?>:</b> <?php echo $row->customer_id; ?>
	                <br/>
	                <b><?php echo $this->translator('order_customer_name', 'shop');?>:</b>
	                <?php if($this->allow('info', 'customer', 'customer')):?>
	                <a class="t_a_link" href="<?php echo $this->url(array('user_id' => $row->customer_id), 'customer_customer_info');?>"><?php echo $c_name;?> <?php echo ($e_name)?'('.$e_name.')':null;?></a>
	                <?php else:?>
	                <?php echo $c_name;?> <?php echo ($e_name)?'('.$e_name.')':null;?>
	                <?php endif;?>
	            </div>
	        </div>
	    <?php $i++;?>    
	    <?php endif;?>
        <?php endforeach;?>
        </div>
		<?php endif;?>
		<?php endif;?>
			
		<!-- 
	    --  Danh sach cong viec 
	    -->
		<?php if($this->allow('list', 'assignment', 'assignment')):?>
		<div class="t_a_ui_helper_line" style="width: 320px; float: left;">
	        <a href="<?php echo $this->url(array(), 'assignment_assignment_list'); ?>"><h3><?php echo $this->translator('dashboard_index_assignment_list');?></h3></a>
	    </div>
	    <?php if ($this->numAssignment == 0) : ?>
	    <div class="t_a_bottom">
		    <?php echo $this->translator('aissgnment_list_not_found', 'assignment'); ?>
		</div>
	    <?php else:?>
	    <div class="t_a_ui_data_list_header"  style="width: 320px; float: left;">
        	<div style="padding-left: 5px; float: left; width: 105px;"><?php echo $this->translator('assignment_order_id', 'assignment'); ?></div>
        	<div style="float: left;"><?php echo $this->translator('assignment_product_name', 'assignment'); ?></div>
        </div>
        <div class="t_a_bottom">
        <?php $i = 0;?>
        <?php foreach ($this->assignments as $row) : ?>
        <?php if($i<5):?>
        <?php
	        /**
	        * Handle php code at here
	        * ---Get product info
	        * ---Get producer info
	        * ---Get assigner info
	        * ---Get due date
	        **/
	        $product  = isset($this->arrProduct[$row->assignment_id])?$this->arrProduct[$row->assignment_id]:null;
	        $producer = isset($this->arrProducer[$row->assignment_id])?$this->arrProducer[$row->assignment_id]:null;
	        $assigner = isset($this->arrAssigner[$row->assignment_id])?$this->arrAssigner[$row->assignment_id]:null;
	        /*$dueDate  = isset($this->arrDueDate[$row->assignment_id])?$this->arrDueDate[$row->assignment_id]:null;*/
	
	        $p_name = 'null';
	        if($producer){
	            $p_name = (trim($producer->full_name))?$producer->full_name:$producer->user_name;
	        }
	
	        $as_name = 'null';
	        if($assigner){
	            $as_name = (trim($assigner->full_name))?$assigner->full_name:$assigner->user_name;
	        }
	
	        /**
	         *
	        **/
	        $class = '';
	
	        //echo $row->assignment_due_date.'-'.date('Y-m-d');die;
	
	        if($row->assignment_finish_date == ''){
	            if($row->assignment_due_date < date('Y-m-d')){
	                $class = 'style="color:red"';
	            }
	        }
	    ?>
	    <div id="assignmetnRow_<?php echo $row->assignment_id; ?>" class="clearfix t_a_ui_data_list_content">
	    	<div style="float: left; width: 105px;">
	            <div style="padding-left: 0;">
	                <?php echo $row->order_id;?>
	            </div>
	
	            <div class="t_a_top t_a_ui_helper_action">
	                <?php if ($this->allow('view', 'assignment', 'assignment')) : ?>
	                <a href="<?php echo $this->url(array('assignment_id' => $row->assignment_id), 'assignment_assignment_view'); ?>"><?php echo $this->translator('assignment_list_action_view', 'assignment'); ?></a>
	                <?php endif; ?>
	            </div>
	        </div>
	        <div style="width:200px; float: left;padding-left: 5px;"><?php echo ($product)?$product->product_admin_name:null;?></div>
	    </div>
        <?php endif;?>
        <?php $i++;?>
        <?php endforeach;?>
        </div>
	    <?php endif;?>
	    <?php endif;?>
	</div>
</div>
<?php endif;?>
<!-- End: Thong tin DN - SP moi nhat - Danh sach don dat hang - Assignment  -->



<div id="dashboardLayout" style="width: 940px; margin: 0 auto; min-height: 150px; height: 150px"></div>

<div id="messageDialog"></div>

<script type="text/javascript">
var rootContainer = new Tomato.Core.Layout.Container('dashboardLayout');
rootContainer.setBaseUrl('<?php echo $this->baseUrl(); ?>');
rootContainer.setBgColor('#1a1a1a');

$(document).ready(function() {
	$('#customizeButton').toggle(function() {
		$(this).find('span').html('<?php echo $this->escape($this->translator('dashboard_index_close_editor_button')); ?>');
		$('#loading').addClass('t_a_ui_helper_loading').show();
		
		$.ajax({
			url: '<?php echo $this->url(array(), 'core_dashboard_index'); ?>',
			type: 'POST',
			data: { act: 'edit' },
			success: function(response) {
				$('#editor').html(response).show();
				$('#loading').removeClass('t_a_ui_helper_loading').hide();
				$('#layoutButtons').show();

				rootContainer.toggleMode('CONFIG', false);
			}
		});
	}, function() {
		$(this).find('span').html('<?php echo $this->escape($this->translator('dashboard_index_customize_button')); ?>');
		$('#editor').hide();
		$('#layoutButtons').hide();
		rootContainer.toggleMode('PREVIEW', true);
	});

	/**
	 * Switch mode handler
	 */
	$('#switchButton').toggle(function() {
		$(this).find('span').html('<?php echo $this->escape($this->translator('dashboard_index_config_button')); ?>');
		rootContainer.toggleMode('PREVIEW', true);
	}, function() {
		$(this).find('span').html('<?php echo $this->escape($this->translator('dashboard_index_preview_button')); ?>');
		rootContainer.toggleMode('CONFIG', false);
	});

	/**
	 * Save layout handler
	 */
	$('#saveButton').click(function() {
		var layout = $.toJSON(rootContainer.save());
		
		$.ajaxq('dashboard', {
			url: '<?php echo $this->url(array(), 'core_dashboard_index'); ?>',
			type: 'POST',
			data: { act: 'save', layout: layout },
			success: function(response) {
				$('#messageDialog').html('<?php echo addslashes($this->translator('dashboard_index_save_success')); ?>')
					.dialog({
						title: '<?php echo addslashes($this->translator('common_dialog_message')); ?>',
						dialogClass: 't_a_ui_dialog',
						modal: true,
				    	show: { effect: 'fade' },
						open: function(event, ui) {
							setTimeout(function() {
								$('#' + event.target.id).dialog('option', 'hide', 'fade').dialog('destroy');
							}, 3000);
						}
					});
			}
		});
	});

	/**
	 * Load the layout
	 */
	 Tomato.Core.Layout.Lang.setLang({
		CONTAINER_COLS: 		  '<?php echo $this->escape($this->translator('page_layout_container_columns')); ?>',
		CONTAINER_REMOVE_CONFIRM: '<?php echo $this->escape($this->translator('page_layout_remove_container_confirm')); ?>',
		WIDGET_PREVIEW: 		  '<?php echo $this->escape($this->translator('page_layout_widget_preview')); ?>',
		WIDGET_BACK: 			  '<?php echo $this->escape($this->translator('page_layout_widget_back')); ?>',
		WIDGET_REMOVE_CONFIRM: 	  '<?php echo $this->escape($this->translator('page_layout_remove_widget_confirm')); ?>',
		WIDGET_CACHE: 			  '<?php echo $this->escape($this->translator('page_layout_widget_cache')); ?>',
		WIDGET_LOAD_AJAX:		  '<?php echo $this->escape($this->translator('page_layout_widget_load_ajax')); ?>',
		DEFAULT_OUTPUT:			  '<?php echo $this->escape($this->translator('page_layout_default_output')); ?>'
	});

	<?php if ($this->dashboardLayout) : ?>
	rootContainer.load(<?php echo $this->dashboardLayout; ?>, true);
	<?php endif; ?>
});
</script>

